﻿using System.ComponentModel.DataAnnotations;

namespace AiQiuQuan.Sport.Model.Models
{
    /// <summary>
    /// 比赛管理员新增
    /// </summary>
    public class GameManageUserAddDto : IValidatableObject
    {
        /// <summary>
        /// 比赛ID
        /// </summary>
        [Required]
        public Guid GameId { get; set; }

        /// <summary>
        /// 用户列表
        /// </summary>
        [Required]
        [MinLength(1)]
        public List<Guid> UserIdList { get; set; }

        /// <summary>
        /// validate
        /// </summary>
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            foreach (var user in UserIdList)
            {
                if (user == default)
                {
                    yield return new ValidationResult("用户不正确");
                    yield break;
                }

                if (UserIdList.Count(m => m == user) >= 2)
                {
                    yield return new ValidationResult("用户重复");
                    yield break;
                }
            }
        }
    }
}